<template>
  <div class="app-container">
    <el-form :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      class="form-search"
      label-width="100px">
      <el-form-item :label="$t('accountMonitor.operate')"
        prop="operate">
        <el-select v-model="queryParams.operate"
          :placeholder="$t('common.placeholderSelect')"
          clearable
          style="width: 240px">
          <el-option v-for="dict in dict.type.rpa_operate_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('accountMonitor.dateRange')">
        <el-date-picker v-model="dateRange"
          value-format="yyyy-MM-dd"
          type="daterange"
          :clearable="false"
          range-separator="-"
          :start-placeholder="$t('common.startDate')"
          :end-placeholder="$t('common.endDate')"
          style="width: 240px"></el-date-picker>
      </el-form-item>
      <el-form-item :label="$t('accountMonitor.status')"
        prop="status">
        <el-select v-model="queryParams.status"
          :placeholder="$t('common.placeholderSelect')"
          clearable
          style="width: 240px">
          <el-option v-for="dict in dict.type.data_show_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery">{{$t('common.search')}}</el-button>
        <el-button icon="el-icon-refresh"
          size="mini"
          @click="resetQuery">{{$t('common.reset')}}</el-button>
      </el-form-item>
    </el-form>

    <div class="section-box">
      <el-row :gutter="10"
        class="mb8">
        <el-col :span="1.5">
          <el-button type="warning"
            plain
            icon="el-icon-close"
            size="mini"
            @click="handleClose">{{$t('common.close')}}</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="loading"
        :data="dataList">
        <!-- <el-table-column :label="$t('accountMonitor.accountName')"
          align="center"
          prop="accountName"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('accountMonitor.accountNumber')"
          align="center"
          prop="accountNumber"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('accountMonitor.companyName')"
          align="center"
          prop="companyName"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('accountMonitor.bankName')"
          align="center"
          prop="bankName"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('accountMonitor.webUrl')"
          align="center"
          prop="webUrl"
          min-width="200"
          show-overflow-tooltip />
        <el-table-column :label="$t('accountMonitor.lastMonitorTime')"
          align="center"
          prop="lastMonitorTime"
          min-width="160" /> -->
        <el-table-column :label="$t('accountMonitor.computeName')"
          align="center"
          prop="computeName"
          min-width="160"
          show-overflow-tooltip />
        <!-- <el-table-column :label="$t('accountMonitor.ip')"
          align="center"
          prop="ip"
          min-width="160" />
        <el-table-column :label="$t('accountMonitor.macAddress')"
          align="center"
          prop="macAddress"
          min-width="200" /> -->
        <el-table-column :label="$t('accountMonitor.operate')"
          align="center"
          prop="operate"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('accountMonitor.reason')"
          align="center"
          prop="reason"
          min-width="200"
          show-overflow-tooltip />
        <el-table-column :label="$t('accountMonitor.exceptionMsg')"
          align="center"
          prop="exceptionMsg"
          min-width="200"
          show-overflow-tooltip />

        <!-- <template slot-scope="scope">
            <dict-tag :options="dict.type.rpa_operate_type"
              :value="scope.row.status" />
          </template>
        </el-table-column> -->
        <el-table-column :label="$t('accountMonitor.status')"
          align="center"
          min-width="100">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.data_show_status"
              :value="scope.row.status" />
          </template>
        </el-table-column>
        <!-- <el-table-column :label="$t('common.createBy')"
          align="center"
          prop="createBy"
          min-width="140"
          show-overflow-tooltip /> -->
        <el-table-column :label="$t('common.createTime')"
          align="center"
          prop="createTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column :label="$t('common.remark')"
          prop="remark"
          min-width="160"
          show-overflow-tooltip /> -->
        <el-table-column :label="$t('accountMonitor.attachment')"
          align="center"
          prop="attachment"
          min-width="160">
          <template slot-scope="scope">
            <el-button size="mini"
              type="text"
              icon="el-icon-view"
              v-if="scope.row.attachment">
              {{$t('common.view')}}
              <el-image style="width: 100%; height: 100%;position: absolute;top: 0;left: 0;opacity: 0;"
                :src="scope.row.attachmentOne"
                :preview-src-list="scope.row.attachmentList">
              </el-image>
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
  </div>
</template>

<script>
import {
  accountMonitorDetails,
} from "@/api/RPA/rpa.js";

export default {
  name: "U",
  dicts: ["data_show_status", "rpa_operate_type"],
  data () {
    return {
      // 遮罩层
      loading: true,

      // 总条数
      total: 0,
      // 角色表格数据
      dataList: [],

      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cardId: null,
        operate: null,
        startDate: null,
        endDate: null,
        status: null,
      },
      bankListAccount: [],
      bankAccountLoading: false,
    };
  },
  watch: {
    dateRange (val) {
      if (val) {
        this.queryParams.startDate = val[0]
        this.queryParams.endDate = val[1]
      } else {
        this.queryParams.startDate = null
        this.queryParams.endDate = null
      }
    },
  },
  created () {
    this.queryParams.cardId = this.$route.params.cardId
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList () {
      this.loading = true;
      accountMonitorDetails(this.queryParams).then(
        (response) => {
          response.rows.forEach(item => {
            if (item.attachment) {
              item.attachmentList = item.attachment.split(',')
              item.attachmentOne = item.attachmentList[0]
            } else {
              item.attachmentList = []
              item.attachmentOne = ''
            }
          })
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 返回按钮
    handleClose () {
      const obj = { path: '/OTP/accountMonitoring' };
      this.$tab.closeOpenPage(obj);
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.dateRange = []
      this.queryParams.startDate = null
      this.queryParams.endDate = null
      this.handleQuery();
    },
  },
};
</script>
